﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using InHD.model;
using InHD.commands;
using System.Windows.Input;

namespace InHD.viewmodels
{
    /// <summary>
    /// Hien cac transactions, click vao 1 transaction se mo form acc receivable
    /// </summary>
    class AccReceivableList2ViewModel:WorkspaceViewModel
    {
        #region Value Property
        private List<Transaction> _transactionRowCollection;
        private int _transactionRowIndex = -1;
        public string commandExcute = string.Empty;
        private Transaction _transaction;
        #endregion

        #region Constructor
        public AccReceivableList2ViewModel(List<Transaction> listTrans)
        {
            _transactionRowCollection = listTrans;
        }
        #endregion

        #region Presentation Property
        public List<Transaction> TransactionRowCollection
        {
            get
            {
                return _transactionRowCollection;
            }
            set
            {
                if (_transactionRowCollection != value)
                {
                    _transactionRowCollection = value;
                    OnPropertyChanged("TransactionRowCollection");
                }
            }
        }

        public int TransactionRowIndex
        {
            get
            {
                return this._transactionRowIndex;
            }
            set
            {
                this._transactionRowIndex = value;
                OnPropertyChanged("TransactionRowIndex");
            }
        }

        public Transaction SelectedTransaction
        {
            get
            {
                return this._transaction;
            }
            set
            {
                if (value != null)
                {
                    this._transaction = value;
                }
            }
        }
        #endregion

        #region Command 
        private RelayCommand _viewTransactionDetailCommand;
        public ICommand ViewTransactionDetailCommand
        {
            get
            {
                if (_viewTransactionDetailCommand == null)
                {
                    _viewTransactionDetailCommand = new RelayCommand(
                        (param) => this.ViewTransactionDetail(), (param) => this.CanView);
                }
                return _viewTransactionDetailCommand;
            }
        }

        private RelayCommand _closeTransactionListCommand;
        public ICommand CloseTransactionListCommand
        {
            get
            {
                if (_closeTransactionListCommand == null)
                {
                    _closeTransactionListCommand = new RelayCommand(
                        (param) => this.CloseTransactionList());
                }
                return _closeTransactionListCommand;
            }
        }

        #endregion

        #region Command Method
        void ViewTransactionDetail()
        {
            commandExcute = "ViewTransactionDetail";
            OnRequestClose();
        }

        void CloseTransactionList()
        {
            commandExcute = "CloseTransactionList";
            OnRequestClose();
        }

        public bool CanView { get { return this.SelectedTransaction != null ? true : false; } }
        #endregion
    }
}
